package com.xhcl.system.service.impl;

import java.util.List;
import java.util.ArrayList;
import com.xhcl.common.core.domain.Stree;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.xhcl.system.mapper.TGgYskmMapper;
import com.xhcl.system.domain.TGgYskm;
import com.xhcl.system.service.ITGgYskmService;
import com.xhcl.common.core.text.Convert;

/**
 * 预算科目Service业务层处理
 * 
 * @author xhcl
 * @date 2020-08-25
 */
@Service
public class TGgYskmServiceImpl implements ITGgYskmService 
{
    @Autowired
    private TGgYskmMapper tGgYskmMapper;

    /**
     * 查询预算科目
     * 
     * @param yskm 预算科目ID
     * @return 预算科目
     */
    @Override
    public TGgYskm selectTGgYskmById(String yskm)
    {
        return tGgYskmMapper.selectTGgYskmById(yskm);
    }

    /**
     * 查询预算科目列表
     * 
     * @param tGgYskm 预算科目
     * @return 预算科目
     */
    @Override
    public List<TGgYskm> selectTGgYskmList(TGgYskm tGgYskm)
    {
        return tGgYskmMapper.selectTGgYskmList(tGgYskm);
    }

    /**
     * 新增预算科目
     * 
     * @param tGgYskm 预算科目
     * @return 结果
     */
    @Override
    public int insertTGgYskm(TGgYskm tGgYskm)
    {
        return tGgYskmMapper.insertTGgYskm(tGgYskm);
    }

    /**
     * 修改预算科目
     * 
     * @param tGgYskm 预算科目
     * @return 结果
     */
    @Override
    public int updateTGgYskm(TGgYskm tGgYskm)
    {
        return tGgYskmMapper.updateTGgYskm(tGgYskm);
    }

    /**
     * 删除预算科目对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteTGgYskmByIds(String ids)
    {
        return tGgYskmMapper.deleteTGgYskmByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除预算科目信息
     * 
     * @param yskm 预算科目ID
     * @return 结果
     */
    @Override
    public int deleteTGgYskmById(String yskm)
    {
        return tGgYskmMapper.deleteTGgYskmById(yskm);
    }

    /**
     * 查询预算科目树列表
     * 
     * @return 所有预算科目信息
     */
    @Override
    public List<Stree> selectTGgYskmTree(TGgYskm tggyskm)
    {   
    	if (tggyskm!=null && tggyskm.getYskm()!=null){
    		tggyskm.getParams().put("yskm", tggyskm.getYskm());
    	}
        List<TGgYskm> tGgYskmList = tGgYskmMapper.selectTGgYskmList(tggyskm);
        List<Stree> ztrees = new ArrayList<Stree>();
        for (TGgYskm tGgYskm : tGgYskmList)
        {
            Stree ztree = new Stree();
            ztree.setId(tGgYskm.getYskm());
            ztree.setpId(tGgYskm.getSjyskm());
            ztree.setName(tGgYskm.getYskm()+"-"+tGgYskm.getYskmmc());
            ztree.setTitle(tGgYskm.getYskmmc());
            ztrees.add(ztree);
        }
        return ztrees;
    }
}
